#include <QInputDialog>

#include "fenetre.h"
#include "mythread.h"

int main(int argc, char **argv)
{
    QApplication App(argc, argv);

    bool ok = false;
    QString addr = QInputDialog::getText(NULL, "Adresse IP", "Adresse IP du serveur", QLineEdit::Normal, QString("162.38.27.83"), &ok);

    while (!ok || addr.isEmpty())
    {
        if (!ok)
        { return 0; }
        addr = QInputDialog::getText(NULL, "Adresse IP", "Adresse IP du serveur", QLineEdit::Normal, QString("162.38.27.83"), &ok);
    }

    ok = false;
    int port = QInputDialog::getInt(NULL, "Port", "Numero de port", 50000, 1001, 59999, 1, &ok);

    while ((!ok || port < 1000) || port > 60000)
    {
        if (!ok)
        { return 0; }
        port = QInputDialog::getInt(NULL, "Port", "Numero de port", 50000, 1001, 59999, 1, &ok);
    }

    bool b = true;

    MyThread* mt = new MyThread(addr.toStdString(), port, &b);
    mt->start();

    if (!b)
    { return 0; }

    Fenetre* mf = new Fenetre(mt->getClient(), mt);
    mf->show();

    return App.exec();
}

